<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>

	function Person(){
		
	};
	Person.prototype.name='blue';
	
	Person.prototype.age=18;
	
	Person.prototype.job='daza';
	
	Person.prototype.showName=function(){
		console.log(this.name);	
	};
	
	Person.prototype.showAge=function(){
		console.log(this.age);	
	};
	
	var person1=new Person();
	
	var person2=new Person();
	
	//原型与in操作符
	//有两种方式使用in操作符：单独使用和在for-in循环中使用。在单独使用时，in操作符会在通过对象能够访问给定属性时返回ture，无论该属性是存在于实例中还是原型中
	console.log('name' in person1);//true;
	
	person1.name=888;
	console.log('name' in person1);//true;
	
	console.log('age' in person2);//true;
	
	//判断属性是存在于对象中还是原型中
	function hasPrototypeProperty(object, name){
		
		return !object.hasOwnProperty(name) && (name in object);	
	};
	
	console.log(hasPrototypeProperty(person1, 'name'));//false
	
	delete person1.name;
	
	console.log(hasPrototypeProperty(person1, 'name'));//true
	
	
	
	
</script>
</head>

<body>
</body>
</html>
 